package com.doudoukeji.service.Activity.my.edituser.editusername;

import org.apache.commons.lang3.StringUtils;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.doudoukeji.service.Activity.my.edituser.EditUserInfoPresenter;
import com.doudoukeji.service.Activity.my.edituser.EditUserInfoView;
import com.doudoukeji.service.Bean.Token;
import com.doudoukeji.service.R;
import com.sanhai.android.mvp.EduActivity;


//编辑名称的界面
public class NameEditorActivity extends EduActivity implements EditUserInfoView {
    // topbar
    private TextView mTvTitle, mTvFinish;
    // 当前界面
    private EditText mEtName;
    private String nickName = "";
    private EditUserInfoPresenter presenter;

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_nameeditor);
    }

    @Override
    public void init() {
        mTvTitle = (TextView) findViewById(R.id.tv_title);
        mTvTitle.setText("我的姓名");
        mTvFinish = (TextView) findViewById(R.id.tv_finish);
        mTvFinish.setVisibility(View.VISIBLE);
        mTvFinish.setText("完成");
        mTvFinish.setOnClickListener(this);
        // 当前界面
        mEtName = (EditText) findViewById(R.id.et_name);
        if (StringUtils.isNotBlank(Token.getName())) {
            mEtName.setText(Token.getName());
        }

        presenter = new EditUserInfoPresenter(this, this);

    }

    @Override
    public void onClickEvent(View view) {
        switch (view.getId()) {
            case R.id.tv_finish:
                if (checkValue()) {
                    presenter.updateUserInfo("", "", nickName, "", "");
                }
                break;
            default:
                break;
        }
    }


    public boolean checkValue() {
        nickName = mEtName.getText().toString().trim();
        if (StringUtils.isBlank(nickName)) {
            Toast.makeText(NameEditorActivity.this, "姓名不能为空",
                    Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }

    @Override
    public void updateSucced() {
        showToastMessage("修改成功");
        Token.setName(nickName);
        finish();
    }

    @Override
    public void updateFail() {
        showToastMessage("修改失败");
    }
}
